package com.xiaobawang.knowledge.spider.model.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @description 接口统一响应体
 * @author 18101119
 * @date 2024/10/17 9:27
 * @email songxinhang2023@e-chinalife.com
 * @id 18101119
 * @phone 13001321080
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResponseDTO<T> {
    private T data;                   // 具体的数据内容
    private int code;                 // 响应状态码
    private String message;           // 响应消息

    public static <T> ResponseDTO<T> success(T data) {
        return ResponseDTO.<T>builder()
                .code(200)
                .message("success")
                .data(data)
                .build();
    }

    public static <T> ResponseDTO<T> error(int code, String message) {
        return ResponseDTO.<T>builder()
                .code(code)
                .message(message)
                .build();
    }

    public static <T> ResponseDTO<T> error(int code, String message, T data) {
        return ResponseDTO.<T>builder()
                .code(code)
                .message(message)
                .data(data)
                .build();
    }
}